package com.adlx.dingdong.mall.controller.v1;

import com.adlx.dingdong.mall.controller.BaseController;
import com.adlx.dingdong.mall.dto.Result;
import com.adlx.dingdong.mall.user.api.UserFeignClient;
import com.adlx.dingdong.mall.user.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by dulei on 18/1/10.
 */
@RestController
@RequestMapping(value = {"/v1/user"})
public class UserController extends BaseController {

    @Autowired
    private UserFeignClient userFeignClient;

    @RequestMapping("/currentUser")
    public Result<UserVO> getCurrentUser() {
        Integer uid = getCurrentUid();
        Assert.notNull(uid, "用户ID不能为空");
        //安全对象拿到用户id
        UserVO userVO =  userFeignClient.get(uid.longValue());
        return Result.success(userVO);
    }

    @RequestMapping(value = "/regUser",method = RequestMethod.POST)
    public UserVO regUser() {
        Integer uid = getCurrentUid();
        Assert.notNull(uid, "用户ID不能为空");
        //安全对象拿到用户id
        return null;
    }



    @RequestMapping("/info")
    public UserVO getCurrentInfo() {
        //安全对象拿到用户id
        return userFeignClient.get(1L);
    }

    @RequestMapping("/get/{uid}")
    public Result<UserVO> get(@PathVariable("uid") Long uid) {
        //安全对象拿到用户id
        return Result.success(userFeignClient.get(uid));
    }


}
